<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/3
 * Time: 19:46
 */

namespace app\api\service;


use app\api\model\ThirdApp;
use app\lib\enum\ScopeEnum;
use app\lib\Exception\TokenException;

class AppToken extends Token
{
    public function get($account, $password){
    // 加密
        $salt = config('secure.third_salt');
        $pwd = md5($password.$salt);

        $result = ThirdApp::check($account, $pwd);
        if(!$result){
            throw new TokenException([
                'info'=>'授权失败'
            ]);
        }

        //生成token  缓存  返回
        $cache = [
            'uid' => $account,
            'scope' => ScopeEnum::Super
        ];

        return self::saveCache($cache);
        // return true;
    }
}